// pages/payPop/payPop.js
var app = getApp();

Component({
  properties: {
    com_data: {
      type: Object,
      value: ""
    },
    show_com: {
      type: Number,
      value: ""
    },
    cou_index: {
      type: Array,
      value: ""
    },
    pop_show: {
      type: Boolean,
      value: !0
    },
    choose_pref: {
      type: Boolean,
      value: !0
    }
  },
  data: {
    baby_index: 0,
    pay_index: 0
  },
  ready: function(){
    var that = this;
    
  },
  methods: {
    return:function(){},
    close_pop:function(){
      var pop_show = !this.properties.pop_show;
      this.triggerEvent('closePop', {pop_show})
    },
    add_bady:function(){
      this.close_pop();
      var userinfo=wx.getStorageSync('userinfo')
      wx.navigateTo({
        url: '../../mypage/addBady/addBaby?id='+userinfo.id,
      })
      // 事件统计
      app.td_app_sdk.event({
        id: 'addBady',
        label: '添加宝宝',
        params: {
          key1: "课程套餐支付"
        }
      })
    },
    // 选择宝宝
    check_baby:function(e){
      var that = this;
      var index = e.currentTarget.dataset.index;
      that.setData({baby_index: index})
      // 事件统计
      app.td_app_sdk.event({
        id: 'checkBaby',
        label: '选择宝宝',
        params: {
          key1: "课程套餐支付"
        }
      })
    },
    confirm_baby:function(){
      var that = this;
      var res_data = {pop_show: !this.properties.pop_show,baby_index:that.data.baby_index}
      this.triggerEvent('checkBaby', {res_data})
    },
    // 选择优惠卷
    // 机构
    check_business_cou:function(e){
      var index = e.currentTarget.dataset.index,cou_index=this.properties.cou_index;
      if(cou_index[0]==index){
        cou_index[0]=10000
      }else{
        cou_index[0]=index;
      }
      this.triggerEvent('checkBusiness',cou_index)
      // 事件统计
      app.td_app_sdk.event({
        id: 'checkPref',
        label: '选择优惠券',
        params: {
          key1: "机构券"
        }
      })
    },
    // 平台
    check_terr_cou:function(e){
      var choose_pref=this.properties.choose_pref,cou_index=this.properties.cou_index;
      var index = e.currentTarget.dataset.index;
      if(choose_pref){
        if(cou_index[1]==index){
          cou_index[1]=10000
        }else{
          cou_index[1]=index;
        }
        this.triggerEvent('checkTerr',cou_index)
      }else{
        console.log('---你选不了---')
      }
      // 事件统计
      app.td_app_sdk.event({
        id: 'checkPref',
        label: '选择优惠券',
        params: {
          key1: "平台券"
        }
      })
    },
    confirm_cou:function(){
      this.close_pop()
    },
    // 选择付款方式
    check_pay: function(e){
      var that = this;
      var index = e.currentTarget.dataset.index;
      that.setData({pay_index: index})
    },
    confirm_pay:function(){
      var that = this;
      var res_data = {pop_show: !this.properties.pop_show,pay_index:that.data.pay_index}
      this.triggerEvent('checkPay', {res_data})
    },
  },
});